#ifndef _CIRCLEBUFFER_H
#define _CIRCLEBUFFER_H

#ifdef __cplusplus
extern "C" {
#endif

#include "common_inc.h"
#include "user_define.h"

#define UART1_TXD_BUFF_ROW_SUM 20    	//串口发送缓冲区行数
#define UART1_TXD_BUFF_ROW_SIZE (256+10) 		//串口发送缓冲区行大小
extern char Uart1TxdBuffer[UART1_TXD_BUFF_ROW_SUM][UART1_TXD_BUFF_ROW_SIZE];    //串口发送缓冲区数组

#define UART1_RXD_BUFF_ROW_SUM 20    	//串口接收缓冲区行数
#define UART1_RXD_BUFF_ROW_SIZE (256+10) 		//串口接收缓冲区行大小
extern char Uart1RxdBuffer[UART1_RXD_BUFF_ROW_SUM][UART1_RXD_BUFF_ROW_SIZE];    //串口接收缓冲区数组

#define UART5_TXD_BUFF_ROW_SUM 5    	//串口发送缓冲区行数
#define UART5_TXD_BUFF_ROW_SIZE (100+10) 		//串口发送缓冲区行大小
extern char Uart5TxdBuffer[UART5_TXD_BUFF_ROW_SUM][UART5_TXD_BUFF_ROW_SIZE];    //串口发送缓冲区数组

#define UART5_RXD_BUFF_ROW_SUM 10    	//串口接收缓冲区行数
#define UART5_RXD_BUFF_ROW_SIZE (100+10) 		//串口接收缓冲区行大小
extern char Uart5RxdBuffer[UART5_RXD_BUFF_ROW_SUM][UART5_RXD_BUFF_ROW_SIZE];    //串口接收缓冲区数组

#define WRITE_LOG_BUFF_ROW_SUM 10    	//串口接收缓冲区行数
#define WRITE_LOG_BUFF_ROW_SIZE (256+10) 		//串口接收缓冲区行大小
extern char WriteLogBuffer[WRITE_LOG_BUFF_ROW_SUM][WRITE_LOG_BUFF_ROW_SIZE];    //串口接收缓冲区数组

/*
 *缓冲区类型
 */
struct CircleBuffer{
    char* const pBuffer;                		//缓冲区首地址
    const unsigned int RowSum;           		//缓冲区行数
   	const unsigned int RowSize;        		 	//缓冲区行大小
    unsigned int NextReadRowIdx;  		 		//下次读取的行下标
    unsigned int NextWriteRowIdx; 		 		//下次写入的行下标
    unsigned int UnReadRowSum;     		 		//还未读取的行数
    unsigned int NextWriteIdxInRow;      		//下次写入行的下次写入的位置
    //下面两个元素暂未使用
    const unsigned int DataTypeIdx;      		//表示数据类型的标志在行中的位置
    const unsigned int DataSizeIdx;      		//表示数据本身大小的信息在行中的位置
};



extern struct CircleBuffer Uart1TxdCirclebuff,Uart5TxdCirclebuff;
extern struct CircleBuffer Uart1RxdCirclebuff,Uart5RxdCirclebuff;

extern struct CircleBuffer WriteLogCirclebuff;



extern unsigned int WriteCircleBuff(struct CircleBuffer *circleBuffer,char *data,unsigned int size );
extern unsigned int ReadCircleBuff_ToBuff(struct CircleBuffer *circleBuffer,char *readBuff,unsigned int readBuffSize );
extern char* ReadCircleBuff_ReturnAddr(struct CircleBuffer *circleBuffer);
extern unsigned int SaveRowAndToNextRow(struct CircleBuffer *circleBuffer);
extern unsigned int WriteOnebyteToCircleBuff(struct CircleBuffer *circleBuffer,unsigned char data);
extern unsigned int ClearNextRow(struct CircleBuffer *circleBuffer);
extern unsigned int GetThisRowDataLen(unsigned char* pRead);
extern void CleanAllUnReadRow(struct CircleBuffer *circleBuffer);

#ifdef __cplusplus
}
#endif

#endif

